# 编写测试脚本
# 主要解决：
    # 测试数据
    # 断言
    # 关联


#  导包
from api.order import OrrderAPI
from common.addutil import build_data
import pytest
import config


# 创建测试类
class TestGetAPI:
    id666 =None

    # 前置处理
    def setup(self):
        # 实例化接口类
        self.get_api = OrrderAPI()

    # 获取订单成功
    def test01_get_success(self):
        # 获取响应数据
        response = self.get_api.get()
        print(response.json())
        # 断言
        assert response.status_code == 200

    # 创建订单
    @pytest.mark.parametrize("get_data", build_data(config.BASE_PATH + "/data/add.json"))
    def test02_add_success(self, get_data):
        # add_data = {"products": [{
        #     "product_id": 1,
        #     "count": 1}]}
        response = self.get_api.add(get_data)
        print(response.json())
        TestGetAPI.id666 = response.json().get("order_id")
        print(TestGetAPI.id666)

    # 查看订单
    def test03_select_success(self):
        response = self.get_api.select()
        print(response.json())
        assert response.status_code == 200

